﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using AMStudio.Windows.Forms;
using AMStudio.DelegateDispather;
using AMStudio.Common;
using AccessDB;

namespace AMStudio.UserInterface
{
    public partial class StationUI12 : StationUI
    {
        public StationUI12()
        {
            this.UIName = "StationUI12";
            //this.StationIndex = 12;
            InitializeComponent();
        }

        private void StationUI12_Load(object sender, EventArgs e)
        {
            base.SubscribeEvent("MANAGER_RET");
        }

        protected override void BackGroud_EventHandler(object sender, DelegateDispather.StationEventArgs e)
        {
            base.BackGroud_EventHandler(sender, e);
            switch (e.Command)
            {
                case "DISPATCH_MATERIAL_NR":
                    {
                        string[] ret = (string[])e.Value;
                        //this.textBox3.Text = ret[0];
                        //this.textBox4.Text = ret[1];
                    }
                    break;
                case "CHECK_MATERIAL_ERROR":
                    {
                        //MessageBox.Show("物料不对！请重新扫描物料！");
                        this.textBoxX11.Text = "";
                    }
                    break;
                case "SCAN_MATERIAL":
                    {
                        //todo
                        //提示扫描箱号
                        MessageBox.Show("物料已经用完，请新的扫描物料箱条码！");
                    }
                    break;
                case "TEST_ITAC_CSN":
                    {
                        //todo
                        //提示扫描箱号
                        this.textBoxX8.Text = e.Value.ToString();
                    }
                    break;
            }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            SendMessage("connect", null);
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            SendMessage("disconnect", null);
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            SendMessage("stationsetup", null);
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {
            SendMessage("activatebox", null);
        }

        private void buttonX7_Click(object sender, EventArgs e)
        {
            SendMessage("bomcheck", null);
        }

        private void buttonX16_Click(object sender, EventArgs e)
        {
            SendMessage("createnewbox", null);
        }

        private void buttonX17_Click(object sender, EventArgs e)
        {
            SendMessage("addsntobox", null);
        }

        private void buttonX18_Click(object sender, EventArgs e)
        {
            SendMessage("dispatch", null);
        }

        private void buttonX19_Click(object sender, EventArgs e)
        {
            SendMessage("createcustomersnr", null);
        }


        private void buttonX26_Click(object sender, EventArgs e)
        {
            //todo
            //print
        }

        private void buttonX25_Click(object sender, EventArgs e)
        {
            SendMessage("SET_EXISTING_BOX", this.textBoxX4.Text);
        }

        private void buttonX21_Click(object sender, EventArgs e)
        {
            object obj = (object)(new object[]{textBoxX7.Text, textBoxX9.Text, textBoxX10.Text});
            SendMessage("TEST_ITAC", obj);
        }

        private void buttonX4_Click_1(object sender, EventArgs e)
        {
            SendMessage("checkmaterial", textBoxX11.Text);
        }
		
		

 		private void buttonX7_Click_1(object sender, EventArgs e)
        {
            SendMessage("DISPATCH_PRINT", comboBox1.Text);
        }

        private void comboBox1_DropDown(object sender, EventArgs e)
        {
            DataTable dt = AccessHelper.dataTable("select top 20 * from DISPATCH ORDER BY ID DESC");
            if (dt.Rows.Count > 0)
            {
                comboBox1.DataSource = dt;
                comboBox1.DisplayMember = "BOXNR";
            }
        }




        protected override void SetUserPrivilige(object sender, EventArgs e)
        {
            base.SetUserPrivilige(sender, e);
            User current = UserDB.CurrentLoginUser;
            //Control[] findCtl = null;
            switch (current.AuthorizationSet)
            {
                case 0:
                    this.tabItemMaintenace.Visible = true;
                    this.tabItemConfiguration.Visible = true;
                    this.tabItemRFTag.Visible = true;
                    this.tabItemIput.Visible = true;
                    //this.tabItemOutput.Visible = true;
                    break;
                case 1:
                    this.tabItemMaintenace.Visible = true;
                    this.tabItemConfiguration.Visible = false;
                    this.tabItemRFTag.Visible = false;
                    this.tabItemIput.Visible = false;
                    //this.tabItemOutput.Visible = false;
                    break;
                case 2:
                default:
                    this.tabItemMaintenace.Visible = false;
                    this.tabItemConfiguration.Visible = false;
                    this.tabItemRFTag.Visible = false;
                    this.tabItemIput.Visible = false;
                    //this.tabItemOutput.Visible = false;
                    break;
            }
        }
    }
}
